package com.yanxinim.cn.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.yanxinim.cn.R;
import com.yanxinim.cn.bean.redpacket.MySubordinateInfo;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by ChenXL on 2019/6/25.
 * <p>
 * 我的上下级适配器
 */

public class MySubordinateAdapter extends RecyclerView.Adapter<MySubordinateAdapter.ViewHolder> {

    public static final String TAG = MySubordinateAdapter.class.getName();

    private Context mContext;
    private LayoutInflater mInflater;
    private List<MySubordinateInfo> items = new ArrayList<>();

    public MySubordinateAdapter(Context context) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
    }

    public void setItems(List<MySubordinateInfo> items) {
        this.items = items;
    }
    public void addItems(List<MySubordinateInfo> items) {
        this.items.addAll(items);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_my_subordinate, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        if (items.size() > position && items.get(position) != null) {
            MySubordinateInfo bean = items.get(position);
            holder.userNameTV.setText("用户名：" + bean.getUsername());
            holder.rechargeTV.setText("充值：" + bean.getTotalTecharge() + "元");
            holder.sendAmountTV.setText("发红包：" + bean.getSendPacket() + "元");
            holder.differenceBalanceTV.setText("领发红包相差：" + bean.getPacketDiff() + "元");
        }
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mOnItemClickListener.onItemClick(v, position);
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return items == null ? 0 : items.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        final TextView userNameTV;
        final TextView rechargeTV;
        final TextView sendAmountTV;
        final TextView differenceBalanceTV;

        public ViewHolder(View view) {
            super(view);
            userNameTV = (TextView) view.findViewById(R.id.user_name_tv);
            rechargeTV = (TextView) view.findViewById(R.id.recharge_tv);
            sendAmountTV = (TextView) view.findViewById(R.id.send_amount_tv);
            differenceBalanceTV = (TextView) view.findViewById(R.id.difference_balance_tv);
        }
    }
}
